#include <stdio.h>

#define N       7

int week[N], count;

void print()
{
    int i;

    for (i = 0; i < N; i++) {
        printf("day %d: monk %d\n", i+1, week[i]);
    }
    printf("\n");

    count ++;
}

int cando(int i, int day)
{
    switch(i)
    {
        case 1: return ((day==2||day==4)&&!week[day-1])?1:0;
        case 2: return ((day==1||day==6)&&!week[day-1])?1:0;
        case 3: return ((day==3||day==7)&&!week[day-1])?1:0;
        case 4: return (day==5&&!week[day-1])?1:0;
        case 5: return ((day==1||day==4||day==6)&&!week[day-1])?1:0;
        case 6: return ((day==2||day==5)&&!week[day-1])?1:0;
        case 7: return ((day==3||day==6||day==7)&&!week[day-1])?1:0;
    }
}

void monk()
{
    int i, j, set, haveset[N];

    for (i = 0; i < N; i++) 
        haveset[i] = 0;

    for (i = 1; i <= N; i++) {
        for (j = haveset[i-1]+1, set=0; j <= N; j++) {
            if (cando(i, j))
            {
                week[j-1] = i;
                set = 1;
                haveset[i-1] = j;
                
                if (i == N)
                {
                    print();
                    set = 0;
                    week[j-1] = 0;
                }

                break;
            }
        }

        if (set == 0)
        {
            if (i == 1)
            {
                printf("total: %d\n", count);
                return ;
            }
            
            week[haveset[i-2]-1] = 0;
            haveset[i-1] = 0;
            i -= 2;
        }
    }
}

int main(int argc, char *argv[])
{
    monk(); 
    return 0;
}
